#lang r5rs
(define (montcarlo times experiment)
  (define (once-iter now-time success)
    (if(= 0 now-time)
       (/ success times)
       (once-iter (- now-time 1) (if (experiment)
                                     (+ success 1)
                                     (success)))))
  (once-iter times 0))

(define (estimate-pi a b c)
  (define (square x) (* x x))
  (define (experiment)
    (define (p x y)
      (< ((square (- x a)) + (square (- y b))) (square c)))
    (p (rand) (rand))
    )
  (* (montcarlo 10000 experiment) 4))
(estimate-pi 5 7 3)
(define (rand x)
  (define y random-init)
  (cond ((eq? x 'generate) 
         (begin
           (lambda () (set! y (rand-update y)))
           y))
        ((eq? x 'reset)
         (lambda (x) (set! y x))))) 